﻿using UnityEngine;
using System.Collections;
using ProtoBuf.Message;

namespace Room
{

    public class RCUIUnionGate : RCUIBase
    {
        float hp,maxHp;
        GameObject hpBar;
        UISprite hpSprite;
        public RCUIUnionGate(RoomCharactor owner)
                   : base(owner)
        {
            type = UIType.UnionGate;
            ClickRange = 10f;
        }

        public void Init(InstUFGate gate)
        {
            hp = (float)gate.hp;
            maxHp = (float)gate.maxHp;
            if(hpBar == null)
            {
                hpBar = CreateHpBar();
            }
        }

        GameObject CreateHpBar()
        {
            GameObject obj = null;
            hpSprite = obj.GetComponent<UISprite>();
            obj.transform.localPosition = Vector3.zero;
            obj.transform.localScale = Vector3.one;
            obj.transform.SetParent(uiObj.transform);
            ShowHpBar(false);
            return obj;
        }

        public void SetHp(float currHp)
        {
            currHp = Mathf.Clamp(currHp, 0f, maxHp);
            hpSprite.fillAmount = currHp / maxHp;
            ShowHpBar(currHp > 0);
        }

        public void ShowHpBar(bool value)
        {
            hpBar.SetActive(value);
        }
    }
}
